#ifndef __DALELIB_FPSCOUNTER_H__
#define __DALELIB_FPSCOUNTER_H__

#include <mmsystem.h>

namespace dalelib
{
/*******************************************
 all you need to do is create an instance
 of this class and call getFps() every
 frame. That's all!
 *******************************************/

class FPSCounter
{
private:

	float _fps;
	float _last_time;
	int _frames;
	float _time;

public:

	FPSCounter() : _fps(0.0f), _last_time(0.0f), _frames(0), _time(0.0f) { }
	~FPSCounter() { }
	float getFps(void) { update(); return _fps; }
	void update(void)
	{
		_time = timeGetTime()*0.001f;
		++_frames;
		if(_time-_last_time>1.0f)
		{
			_fps = float(_frames)/(_time-_last_time);
			_last_time = _time;
			_frames = 0;
		}
	}
};

} // namespace dalelib


#endif
